<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>删除事件</title>


    <style>
        div {
            width: 100px;
            height: 100px;
            background-color: antiquewhite;
        }
    </style>


</head>

<body>

    <div>1</div>
    <div>2</div>



</body>
<script>
    var div = document.querySelectorAll('div');
    //传统事件解绑
    div[0].onclick = function() {
        alert('1');
        //传统方式解绑
        this.onclick = null;
    }

    var a = function() {
        alert('2');
        this.removeEventListener('click', a);
    }

    div[1].addEventListener('click', a)
</script>

</html>